﻿using AntMovement.Core;
using AntMovement.Core.Attributes;
using AntMovement.Core.IParameter;
using AntMovement.Core.Logic;
using AntMovement.Core.Logic.Base;
using AntMovement.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.Handle.FPCAutomaticPlateSetting
{
    [FlowAttributes(nameof(VisualLocalization), 8)]
    public class VisualLocalization : TaskBase
    {
        private HoldParameter _holdParameter;
        private Ton _ton1 = new Ton();
        private ISingleControl _上料直震;
        public VisualLocalization(ITemporaryParameter temporary, IIOParameter iop, IAxisParameter axisp, IDialogHost dialogHost, ILog log, IHoldParameter holdParameter)
            : base(temporary, iop, axisp, dialogHost, log)
        {
            _temporary.Status_模组运动 = new Core.Model.StationStatusModel();
            _上料直震 = iop.GetSingleControl("直震", "电机");
            _holdParameter = (HoldParameter)holdParameter;
        }

        public override void EmergencyStop()
        {

        }

        public override void Handle()
        {
            if (SignalOn(0))
            {
                if (_temporary.Status_模组运动.SafetyPosition)
                {
                    NextStep();
                }
            }
            if (SignalOn(10))
            {
                _temporary.Status_模组运动.SafetyPosition = false;
                if (_temporary.BackOrientation.Count < 9)
                {
                    _temporary.Orientation = true;
                    NextStep();
                }
                else
                {
                    _step = 0;
                }
            }
            if (SignalOn(20))
            {
                if (!_temporary.Orientation)
                {
                    switch (_temporary.RrsultOrientation)
                    {
                        case 1:
                            _temporary.Status_模组运动.Permit_TakeMaterials = true;
                            NextStep(40);
                            break;
                        case 2:
                            _step = 10;
                            break;
                        case 0:
                            NextStep(5);
                            break;
                    }
                }
            }
            if (SignalOn(25))
            {
                _上料直震.Auto_Open = true;
                _上料直震.Auto_Close = !_上料直震.Auto_Open;
                if (_上料直震.IOStatus)
                {
                    NextStep(5);
                }
            }
            if (SignalOn(30))
            {
                _ton1.Time(_holdParameter.DirectShockTime, true);
                if (_ton1.Out)
                {
                    _ton1.Time(_holdParameter.DirectShockTime, false);
                    NextStep(5);
                }
            }
            if (SignalOn(35))
            {
                _上料直震.Auto_Open = false;
                _上料直震.Auto_Close = !_上料直震.Auto_Open;
                if (!_上料直震.IOStatus)
                {
                    _temporary.Orientation = true;
                    _step = 20;
                }
            }
            if (SignalOn(60))
            {
                if (!_temporary.Status_模组运动.Permit_TakeMaterials)
                {
                    _step = 0;
                }
            }
        }

        public override void Resetting()
        {

        }

        public override void SafeStop()
        {

        }
    }
}
